package com.nimble.smile.common;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by 40722 on 2016/3/31.
 */
public abstract class CommonAdapter<T> extends BaseAdapter {
    protected LayoutInflater mLayoutInflater;
    protected Context mContext;
    protected List<T> mData;

    public CommonAdapter(Context context, List<T> mData) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.mData = mData;
    }

    public void setData(List<T> data) {
        mData = data;
    }

    @Override
    public int getCount() {
        if (mData != null && !mData.isEmpty()) {
            return mData.size();
        }
        return 0;
    }

    @Override
    public T getItem(int position) {
        if (mData.size() > 0) {
            return mData.get(position);
        }
        return mData.get(0);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
